package com.ciwong.epaper.modules.msg.dao;

import com.ciwong.epaper.modules.msg.bean.MessageInfo;
import com.ciwong.epaper.util.SerializableManager;
import com.ciwong.mobilelib.i.BaseCallBack;

import java.io.Serializable;
import java.util.List;

/**
 * Message 相关业务DAO
 * Created by res-yinxue on 2016/6/20.
 */
public class MsgDao {
    private static MsgDao instance;

    private MsgDao() {

    }

    /**
     * 获取唯一实例
     */
    public static MsgDao getInstance() {
        if (instance == null) {
            instance = new MsgDao();
        }
        return instance;
    }

    /**
     * 获取服务器上未读消息
     */
    public void getNetMsgCount(int brandId, long userId,
                               final BaseCallBack callBack) {
        MsgRequest.getNoReadMsgCount(brandId, userId, callBack);

    }



    /**
     * 获取消息列表信息
     */
    public void getMessageList(int brandId, long userId, final BaseCallBack callBack) {
        MsgRequest.getMessageList(brandId, userId, new BaseCallBack() {
            @Override
            public void failed(int errorCode, Object data) {
                callBack.failed(errorCode, data);
            }

            @Override
            public void failed(Object data) {
                callBack.failed(data);
            }

            @Override
            public void success(Object data) {
                List<MessageInfo> infos = (List<MessageInfo>) data;

                SerializableManager.getInstance().serialize(
                        SerializableManager.SerializeKey.SHARE_KEY_MSG_LIST_NEW, (Serializable) infos
                );
                callBack.success(infos);

            }
        });

    }

    /**
     * 获取未读消息数量
     */
    public void getMsgsBySenderId(int brandId,  long userId,int msgGroupType,
                                  int page, int pageSize, final BaseCallBack callBack) {
        MsgRequest.getMsgsBySenderId(brandId, userId,msgGroupType, page, pageSize, callBack);

    }

    /**
     * 上传未读信息的ID
     */
    public void setMsgStateRead(long userId, String msgIds, final BaseCallBack callBack) {
        MsgRequest.setMsgStateRead(userId, msgIds, callBack);
    }

    /**
     * 向服务器发送“推送ID”
     */
    public void setUserPushId(int brandId, long userId, String tagno, int ptypeId,
                              String pushId, final BaseCallBack callBack) {
        MsgRequest.setUserPushId(brandId, userId, tagno, ptypeId, pushId, callBack);

    }

    /**
     * 根据作业ID获得作业详情
     */

    public void getUserWorkDetail(String workId, long userId, final BaseCallBack callBack) {
        MsgRequest.getUserWorkDetail(workId, userId, callBack);
    }

    /**
     * 根据doWorkId获取作业内容
     */
    public void getDoWorkInfoFromNet(String doWorkId,final BaseCallBack callBack){
        MsgRequest.getDoWorkInfoFromNet(doWorkId, callBack);
    }



    /**
     * 新的获取服务器上未读消息
     */
    public void getNetMsgCountNew(String json,
                                  final BaseCallBack callBack) {
        MsgRequest.getNoReadMsgCountNew(json,callBack);

    }
    /**
     * 新的获取消息列表信息
     */
    public void getMessageListNew(String json,final BaseCallBack callBack) {
        MsgRequest.getMessageListNew(json,callBack);
    }

}
